package com.micangcaihang.common.utils;

import android.support.v4.widget.SwipeRefreshLayout;

/**
 * <pre>
 *     author : Fandy
 *     e-mail : fandayonggmail@gmail.com
 *     time   : 2017/04/13
 *     desc   :
 *     version: 1.0
 * </pre>
 */

public class SwipeLayoutHelper {


    private OnSwipeRefreshListener mOnSwipeRefreshListener;

    private SwipeRefreshLayout mSwipeRefreshLayout;

    public SwipeLayoutHelper(SwipeRefreshLayout refreshLayout) {
        this.mSwipeRefreshLayout = refreshLayout;
    }

    private SwipeRefreshLayout.OnRefreshListener mOnRefreshListener = new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            if (null != mOnSwipeRefreshListener) {
                mOnSwipeRefreshListener.onfresh();
            }
        }
    };

    public void autoRefresh() {
        if (null != mOnSwipeRefreshListener) {
            mSwipeRefreshLayout.setRefreshing(true);
            mOnSwipeRefreshListener.onfresh();
        }
    }

    public static interface OnSwipeRefreshListener {
        public void onfresh();
    }

    public void setOnSwipeRefreshListener(OnSwipeRefreshListener onSwipeRefreshListener) {
        this.mOnSwipeRefreshListener = onSwipeRefreshListener;
        mSwipeRefreshLayout.setOnRefreshListener(mOnRefreshListener);
    }
}
